package com.jx.lcs.common.baidu;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jx.lcs.util.common.Constant;

/**
 * 百度推送工具类
 */
public class BaiduPushUtil {
	
	private static Logger logger = LoggerFactory.getLogger(BaiduPushUtil.class);
	
	//根据系统推送消息
	public static void pushNotification(String os, String user_id, Long channel_id, String content, Integer msgNum, String appType) {
		logger.info("--消息推送开始，os："+ os + "，user_id：" + user_id + "，channel_id：" + channel_id + "，content：" + content);
		
		if(user_id != null && !user_id.equals("") && channel_id != null && channel_id > 0) {
			if(msgNum == null) msgNum = 0; 
			if(os != null && os.equals("iOS")) {
				content = "{\"aps\":{\"alert\":\"" + content + "\", \"badge\":" + msgNum + ", \"sound\":\"default\"}}";
				BaiduIOSPushUtil.pushNotification(user_id, channel_id, content, appType);
			} else {
				content = "{\"title\":\"" + Constant.SYS_MESSAGE_DEFAULT_TITLE + "\", \"sound\":\"default\", \"description\":\"" + content + "\"}";
				BaiduAndroidPushUtil.pushNotification(user_id, channel_id, content);
				
				BaiduAndroidPushMsgUtil.pushMessage(user_id, channel_id, String.valueOf(msgNum));
			}
		}
	}

}
